package com.bytedance.improvingroad.banner_test.banner_frags

import com.bytedance.improvingroad.BannerShowActivity
import com.bytedance.improvingroad.BaseFragment
import com.bytedance.improvingroad.R
import com.bytedance.improvingroad.banner_test.BannerModel
import com.bytedance.improvingroad.banner_test.ImageAdapter
import com.bytedance.improvingroad.databinding.IndicatorFragmentBinding
import com.youth.banner.indicator.RectangleIndicator
import com.youth.banner.indicator.RoundLinesIndicator

/**
 * Created by chenxiong
 * date 12/7/21
 */
class IndicatorVFragment: BaseFragment<IndicatorFragmentBinding>(),BannerShowActivity.ChangeIndicatorListener {

    val bannerModels = listOf(
        BannerModel(R.drawable.pic1,"巩俐不低俗，我就不能低俗"),
        BannerModel(R.drawable.pic2,"朴树又回来了，再唱经典老歌引万人大合唱"),
        BannerModel(R.drawable.pic3,"揭秘北京电影如何升级"),
        BannerModel(R.drawable.pic4,"乐视网TV版大派送"),
        BannerModel(R.drawable.pic5,"热血屌丝的反杀"),
    )
    override fun initData() {
        binding.banner.setAdapter(ImageAdapter(bannerModels))
            .setIndicator(binding.indicator,false)
                //添加画廊效果
            .setBannerGalleryEffect(50, 10)
            .addBannerLifecycleObserver(this)
        (activity as BannerShowActivity).changeIndicatorListener = this
    }

    override fun changeIndicator(type: Int) {
        when (type) {
            ROUND_LINE -> binding.banner.setIndicator(RoundLinesIndicator(context))
            ROUND_RECT -> binding.banner.setIndicator(RectangleIndicator(context))
        }
    }

    override fun onDetach() {
        super.onDetach()
        (activity as BannerShowActivity).changeIndicatorListener = null
    }

    companion object {
        const val ROUND_LINE = 1
        const val ROUND_RECT = 2
    }
}